<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="shortcut icon" href="favicon.ico">
    <link href="/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="/css/font-awesome.min.css?v=4.4.0" rel="stylesheet">
    <link href="/css/animate.css" rel="stylesheet">
    <link href="/css/style.css?v=4.1.0" rel="stylesheet">

    <link href="/bootstraptable/bootstrap-table.min.css" rel="stylesheet">
</head>
<body>

<div class="container">
    <div style="text-align: right">
        <button class="btn btn-default" id="update_ManufactureApply">提交</button>
        <button type="button" class="btn btn-default"><a href="javascript:history.back()"
                                                         style="color: black">返回</a></button>

    </div>
    <input type="hidden" name="id" id="id">
    <div class="panel panel-default">
        <div class="panel-heading">
            <div class="h4" align="center">生产工序设计单</div>
        </div>
        <div class="panel-body">
            <div class="form-group">
                <div class="col-sm-6">
                    <label class="col-sm-4 control-label">工单制定人</label>
                    <div class="col-sm-8">
                        <input type="text" name="designer" id="designer"
                               class="form-control text_bottom_border"
                               value="">
                    </div>
                </div>
                <div class="col-sm-6">
                    <div class="col-sm-8">
                    </div>
                </div>
            </div>
            <div class="form-group">
                <div class="col-sm-6">
                    <label class="col-sm-4 control-label">产品名称</label>
                    <div class="col-sm-8">
                        <input type="text" name="productName" id="productName"
                               class="form-control text_bottom_border" style="background-color:white" readonly
                               value="">
                    </div>
                </div>
                <div class="col-sm-6">
                    <label class="col-sm-4 control-label">产品编号</label>
                    <div class="col-sm-8">
                        <input type="text" name="productId" id="productId"
                               class="form-control text_bottom_border" style="background-color:white" readonly
                               value="">
                    </div>
                </div>
            </div>

            <div class="form-group">
                <div class="col-sm-6">
                    <label class="col-sm-4 control-label">数量</label>
                    <div class="col-sm-8">
                        <input type="text" name="amount" id="amount"
                               class="form-control text_no_border" style="background-color:white" readonly>
                    </div>
                </div>
                <div class="col-sm-6">
                    <label class="col-sm-4 control-label">描述</label>
                    <div class="col-sm-8">
                        <input type="text" name="productDescribe" id="productDescribe"
                               class="form-control text_no_border">
                    </div>
                </div>
            </div>
            <!--物料明细表格-->
            <table id="manufactureDesignProcedureDetails_table">

            </table>

            <div class="form-group">
                <div class="col-sm-6">
                    <label class="col-sm-4 control-label">登记人：</label>
                    <div class="col-sm-8">
                        <input type="text" name="register" id="register" class="form-control"
                               value="">
                    </div>
                </div>
                <div class="col-sm-6">
                    <label class="col-sm-4 control-label">登记时间</label>
                    <div class="col-sm-8">
                        <input type="text" name="registerTime" id="registerTime" class="form-control"
                               value="">
                    </div>
                </div>
            </div>
            <div class="form-group">
                <div class="col-sm-6">
                    <label class="col-sm-4 control-label">备注:</label>
                    <div class="col-sm-8">
                        <textarea class="form-control" id="remark" name="remark"></textarea>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<input type="hidden" id="DESIGN_ID">
<!-- 全局js -->
<script src="/js/jquery.min.js?v=2.1.4"></script>
<script src="/js/bootstrap.min.js?v=3.3.6"></script>
<script src="/js/plugins/metisMenu/jquery.metisMenu.js"></script>
<script src="/js/plugins/slimscroll/jquery.slimscroll.min.js"></script>
<script src="/js/plugins/layer/layer.min.js"></script>
<!-- 自定义js -->
<script src="/js/hAdmin.js?v=4.1.0"></script>
<!--<script type="text/javascript" src="/js/index.js"></script>-->

<!-- 第三方插件 -->
<script src="/js/plugins/pace/pace.min.js"></script>

<!--BootstrapTable-->
<script src="/bootstraptable/bootstrap-table.min.js"></script>
<script src="/bootstraptable/locale/bootstrap-table-zh-CN.min.js"></script>
<script>
    $(function () {
        let data = localStorage.getItem("data")
        let pp = $.parseJSON(data)
        $("#productName").val(pp.productName)
        $("#productId").val(pp.productId)
        $("#amount").val(pp.amount)
        $("#productDescribe").val(pp.productDescribe)
        $("#registerTime").val(fortime())
        $.post("/ManufactureDesignProcedure/getOne2", {"productId": pp.productId}, function (res) {
            $("#DESIGN_ID").val(res.designId)
            $("#manufactureDesignProcedureDetails_table").bootstrapTable({
                // 请求方式
                method: "post",
                // 内容类型：如果请求方式是post，内容类型必须是application/x-www-form-urlencoded
                contentType: "application/x-www-form-urlencoded",
                // 请求路径
                url: '/ManufactureDesignProcedure/showDetails',
                // 数据行交替样式
                striped: true,
                // // 是否是服务器端分页：server表示服务器端，client表示前端分页
                // sidePagination: 'server',
                // //初始化加载第一页
                // pageNumber: 1,
                // //是否分页
                // pagination: true,
                // // 单页记录数，页大小
                // pageSize: 2,
                // // 分页列表
                // pageList: [2, 5, 10, 20],
                //刷新按钮
                // showRefresh:true,
                // 请求参数
                queryParams: function (params) {
                    let obj = {
                        // params.limit获取组件中的页大小
                        // params.offset获取请求数据的起始索引
                        // pageSize: params.limit,
                        // pageNo: (params.offset / params.limit) + 1,
                        id: res.id

                    }
                    return obj;
                },

                // 表格列标题
                columns: [{
                    title: "序号",
                    field: "detailsNumber",
                }, {
                    title: "工序名称",
                    field: "procedureName"
                }, {
                    title: "工序编号",
                    field: "procedureId",
                }, {
                    title: "描述",
                    field: "procedureDescribe",
                }, {
                    title: "工时数(小时)",
                    field: "labourHourAmount",
                    formatter: function (value, row, index) {
                        return value * $("#amount").val()
                    }
                }, {
                    title: "单位工时成本(元)",
                    field: "costPrice"
                }, {
                    title: "工时成本小计",
                    field: "subtotal",
                    formatter: function (value, row, index) {
                        return row.labourHourAmount * $("#amount").val() * row.costPrice
                    }
                }, {
                    title: "查看物料",
                    field: "",
                    formatter: function (value, row, index) {
                        return `<a href="javascript:show(${row.id})">查看物料</a>`
                    }
                }]
            })
        })
    })

    function show(id) {
        localStorage.setItem("amount31", $("#amount").val())
        localStorage.setItem("id31", id)
        localStorage.setItem("DESIGN_ID", $("#DESIGN_ID").val())
        window.location = "/produce/create_production_dispatch_work_orders3UI"
    }

    function fortime() {
        let date = new Date();
        let y = date.getFullYear();
        let m = date.getMonth() + 1;
        let d = date.getDate();
        let h = date.getHours();
        let mm = date.getMinutes();
        let s = date.getSeconds();
        return (y + '-' + add(m) + '-' + add(d) + ' ' + add(h) + ':' + add(mm) + ':' + add(s));
    }

    function add(m) {
        return m < 10 ? '0' + m : m
    }

    $("#update_ManufactureApply").click(function () {
        let val_text2 = localStorage.getItem("val_text2")
        let val_text3 = $.parseJSON(val_text2)
        let data = {
            "designer": $("#designer").val()
        }

        let ara22 =val_text3
        data.ara22 = ara22
        $.ajax({
            url: "/ManufactureApply/arr2",
            type: "post",
            data: JSON.stringify(data),
            contentType: "application/json",
            success: function (data) {
                location.href="/design/succeed"

            }
        }, "json")
    })
</script>
</body>
</html>